//
//  ConverterController.m
//  TemperatureConverter
//
//  Created by Wang Shao-chuan on 2010/12/27.
//  Copyright 2010 National Taiwan University. All rights reserved.
//

#import "ConverterController.h"

@implementation ConverterController

- (void) awakeFromNib 
{
	NSLog(@"Awaken from Nib");
	mConverter = [Converter new];
	[mCelsius setMinValue: [mConverter minCelsius]];
	[mFahrenheit setMinValue: [mConverter minFahrenheit]];
	[mKelvin setMinValue: [mConverter minKelvin]];
	[mCelsius setMaxValue: [mConverter maxCelsius]];
	[mFahrenheit setMaxValue: [mConverter maxFahrenheit]];
	[mKelvin setMaxValue: [mConverter maxKelvin]];
	[mCelsius setContinuous:YES];
	[mFahrenheit setContinuous:YES];
	[mKelvin setContinuous:YES];
	
	[mConverter setCelsius:0.0];
	[self updateSliders];
	[self updateTextLabels];
}

- (IBAction)celsiusChanged:(id)sender
{
	NSLog(@"celsius changed");
	[mConverter setCelsius: [mCelsius floatValue]];
	[self updateSliders];
	[self updateTextLabels];

}
- (IBAction)fahrenheitChanged:(id)sender
{
	NSLog(@"fahrenheit changed");
	[mConverter setFahrenheit: [mFahrenheit floatValue]];
	[self updateSliders];
	[self updateTextLabels];
}
- (IBAction)kelvinChanged:(id)sender
{
	NSLog(@"kelvin changed");
	[mConverter setKelvin: [mKelvin floatValue]];
	[self updateSliders];
	[self updateTextLabels];

}
- (void)dealloc
{
	[mConverter release];
	[super dealloc];
}

- (void)updateSliders
{
	[mCelsius setFloatValue:[mConverter celsius]];
	[mFahrenheit setFloatValue:[mConverter fahrenheit]];
	[mKelvin setFloatValue:[mConverter kelvin]];
}

- (void)updateTextLabels
{
	[mCelsiusText setFloatValue:[mConverter celsius]];
	[mFahrenheitText setFloatValue:[mConverter fahrenheit]];
	[mKelvinText setFloatValue:[mConverter kelvin]];
}

@end
